/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package object;

import java.util.Random;
import piece.*;

/**
 *
 * @author XiaoLong
 */
public class PieceCreator {
    //总共有七种颜色的方块

    private final static int COLOR_SIZE = 5;
    private Random random = new Random();

    public Piece createPiece(int x, int y) {
        //随机得到一种颜色(0-6)
        int image = random.nextInt(COLOR_SIZE) + 1;
        Piece piece = initPiece(image);
        piece.setSquaresXLocation(x);
        piece.setSquaresYLocation(y);
        return piece;
    }

    private Piece initPiece(int image) {
        Piece piece = null;
        int pieceType = random.nextInt(19);
        //初始化Piece，随机创建各个大方块
        switch (pieceType) {
            case 0: {
            }
            case 1: {
            }
            case 2: {
                piece = new PieceO(image);
                break;
            }
            case 3: {
            }
            case 4: {
            }
            case 5: {
                piece = new PieceT(image);
                break;
            }
            case 6: {
            }
            case 7: {
                piece = new PieceZ(image);
                break;
            }
            case 8: {
            }
            case 9: {
                piece = new PieceS(image);
                break;
            }
            case 10: {
            }
            case 11: {
            }
            case 12: {
                piece = new PieceL(image);
                break;
            }
            case 13: {
            }
            case 14: {
            }
            case 15: {
                piece = new PieceJ(image);
                break;
            }
            case 16: {
            }
            case 17: {
            }
            case 18: {
                piece = new PieceI(image);
                break;
            }
        }
        return piece;
    }
}
